package com.tianqu.tms.www.member.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.util.DateUtil;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.entity.CarImage;
import com.tianqu.tms.www.member.viewhelper.MemberInputViewHelper;
/**
 * 修改会员基本信息Action
 * 
 * @author tianshifu
 *
 */
public class MemberUDBaseUpdateAction extends TmsAction {
		
	private static final String IMGLIST = "imgList";//图片list
	
	private Logger logger = Logger.getLogger(MemberUDBaseUpdateAction.class);
	
	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");
		
		MemberInputViewHelper view = (MemberInputViewHelper)uc.getAttribute(TmsConstants.VIEWHELP);
		
		//从mapList中取出图片信息set到viewhelp中 替换掉旧图片
		List<CarImage> imgList = new ArrayList<CarImage>();
		if(uc.getAttribute(IMGLIST)!=null)
		{
			imgList = (List<CarImage>)uc.getAttribute(IMGLIST);
		}
		if(imgList!=null)
		{
			//将list中的数据取出set到viewhelp中
			for(int i=0;i<imgList.size();i++)
			{
				CarImage entity = (CarImage)imgList.get(i);
				if(entity.getImgKey().equals(TmsConstants.ONE))
				{
					view.setOrgPhoto(entity.getImgPath());
				}
				if(entity.getImgKey().equals(TmsConstants.TWO))
				{
					view.setBusinessPhoto(entity.getImgPath());
				}
				if(entity.getImgKey().equals(TmsConstants.THREE))
				{
					view.setCardPhoto(entity.getImgPath());
				}
				if(entity.getImgKey().equals(TmsConstants.FIVE))
				{
					view.setMemberZipCode(entity.getImgPath());
				}
			}
			
		}
		if("男".equals(view.getRegisteredCapital())){
			view.setRegisteredCapital("1");
		}else if("女".equals(view.getRegisteredCapital())){
			view.setRegisteredCapital("2");
		}
		view.setRealNameSave(view.getRealName());
		view.setShortNameSave(view.getShortName());
		//直接从uc中读取数据打到前台
		request.setAttribute(TmsConstants.VIEWHELP, view);//直接将会员信息打到前台显示
		logger.debug(this.getClass().getName() + "#execute was completed.");
		return mapping.findForward(TmsConstants.SUCCESS);
	}

}
